import java.applet.Applet;
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
 
 
public class MyPanel extends JPanel implements Runnable{
 
	final int MAX=1000;
	Particle p[];
	int myWidth,myHeight,XCenter,YCenter=400;
	BufferedImage im;
	Graphics g;
	Thread pThread;
	Image image;
	
	public MyPanel(){
		this.setBackground(Color.BLACK);
		myWidth=1300;
		myHeight=1000;
		p=new Particle[MAX];
		for(int i=0;i<MAX;i++){
			p[i]=new Particle();
		}
		im=new BufferedImage(myWidth,myHeight,BufferedImage.TYPE_INT_RGB);
		image=new ImageIcon("snow2.jpg").getImage();
		/*try {  
		    im = ImageIO.read(new File("C:\\Users\\Alienware\\Pictures\\Saved Pictures\\葫芦娃.jpg"));  
		}catch(Exception e) {  
		    e.printStackTrace();  
		}  */
//		img=im.getImage();
		g=im.getGraphics();
		pThread=new Thread(this);
		pThread.start();
	}
	
	 
	
	protected void paintComponent(Graphics g){
		super.paintComponent(g);//整个面板用背景色重画一遍,起到清屏的作用 
		g.drawImage(im,0,0,this.getWidth(),this.getHeight(),null);
	}
 
	public void run() {
//		try{
//        	URL cb;
//        	File f=new File("E:\\音乐\\迷恋.wav");
//        	cb=f.toURL();
//        	AudioClip ac;
//        	ac=Applet.newAudioClip(cb);
//        	ac.play();
//        	ac.loop();//循环播放
//        }catch (MalformedURLException e) {  
//            e.printStackTrace();  
//        }  
		int i,t=0;
		int r=0;
		while(true){
			g.drawImage(image, 0,0,this.getWidth(),this.getHeight(),null);
//			g.clearRect(0, 0, myWidth, myHeight);
			for(i=0;i<MAX;i++){
//				g.fillOval((int)p[i].X+720, (int)p[i].Y+180, 3+i/10, 3+i/10);
                                g.fillOval((int)p[i].X+720, (int)p[i].Y+180, 15, 15);
				p[i].X=p[i].X+p[i].Vx;
				r+=300;
				Color c=new Color(r);
				g.setColor(c);
				if(p[i].X>20){
					 p[i].Y+=p[i].Vy*p[i].time/2000;  
			         p[i].Vy=(int)9.8*p[i].time;  
			         p[i].time++; 
				}
				if(p[i].Y>myHeight){
					p[i].rest();
				}
			}
			
			repaint();
			try{  
		          Thread.sleep(10);  
		       }catch(InterruptedException e){}  
			}
			
	}
        }
	

